import { DepartmentQueryParam, DepartmentItem, DepartmentPageResult, DepartmentFormData } from '@/types/api/sys/Department';
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
//import qs from 'qs';

export default {
	/**
	 * 分页查询数据
	 * @param query
	 * @return AxiosPromise<DepartmentPageResult> 
	 */
	fetchList: function(query?: DepartmentQueryParam): AxiosPromise<DepartmentPageResult> {
		return request({
			url: '/api/sys/SysDepartment/list',
			method: 'get',
			params: query
		})
	},
	fetchAll: function(): AxiosPromise<DepartmentPageResult> {
		return request({
			url: '/api/sys/SysDepartment/list',
			method: 'get',
			params: {pageSize: 10000,parentId:"null"}
		})
	},
	/**
	 * 根据id查询详情
	 * @param {number} id
	 * @return AxiosPromise<DepartmentFormData>
	 */
	fetchOne: function(id: number): AxiosPromise<DepartmentItem> {
		return request({
			url: '/api/sys/SysDepartment/get/' + id,
			method: 'get'
		})
	},
	/**
	 * 根据id删除，多个以英文逗号(,)分割
	 *
	 * @param {number|string} id
	 */
	delete: function(id: any) {
		return request({
			url: '/api/sys/SysDepartment/delete/' + id,
			method: 'get'
			/*,params: { pv }*/
		})
	},
	/**
	 * 添加
	 */
	add: function(data: DepartmentFormData) {
		return request({
			url: '/api/sys/SysDepartment/add',
			method: 'post',
			data
		})
	},
	/**
	 * 更新
	 * @param {Object} data
	 */
	update: function(data: DepartmentFormData) {
		return request({
			url: '/api/sys/SysDepartment/update',
			method: 'post',
			data
		})
	}
}
